<?php
//会员验证
namespace app\common\validate;
use think\Validate;
class User extends Validate{
    protected $rule = [
        'account' => 'require|isMoblie',
        'password' => 'require|alphaNum|length:6,16',
        'nick_name' => 'mbMax:8',
        'real_password'=>'require|confirm:password',
        'sex' => 'in:1,2',
    ];


    protected $message = [
        'account.require' => '请输入登陆账号',
        'account.isMoblie' => '请输入有效的手机号',
        'password.require' => '请输入登陆密码',
        'password.alphaNum' => '密码只能是数字或字母',
        'password.length' => '密码长度应为6-16个字符',
        'nick_name.mbMax' => '昵称不得超过8个字符',
        'real_password.require' => '请输入确认密码',
        'real_password.confirm' => '确认密码错误',
        'sex.in' => '性别错误', 
    ];


    protected $scene = [
        'register' => 'account,password', //注册验证/登陆
        'forget' => 'account,password,real_password',//忘记密码
        'change_info' => 'real_name,sex', //修改个人资料
    ];

    //手机号验证
    protected function isMoblie($mobile){
        if(!is_mobile($mobile)){
            return false;
        }
        return true;
    }

    //验证字符串长度
    protected function mbMax($str,$len){
        if(mb_strlen($str,'utf-8') > $len){
       
            return false;
        }

        return true;
    }
}